package com.agy.filemanager.configuration;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class MyInterceptor extends HandlerInterceptorAdapter {
    public final static String SESSION_KEY = "user";
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
        //登陆验证
        HttpSession session = request.getSession();
        if (session.getAttribute(SESSION_KEY) != null){
            return true;
        }
        // 跳转登录
        response.sendRedirect("/login/landingPage");
        return false;
    }
}
